<?php

require('header.php');
require('table_des_matieres.php');

if (isset($_GET["supprimer"]))
{

	echo '	<form method="POST">';
	
	echo '	<fieldset>
				<legend>'.$language[$_SESSION['lang']]["DeleteInt"].'</legend>
				<table>
					<tr>
						<td>
							<label class = "text" for = "intermconnu">'.$language[$_SESSION['lang']]["ChooseKnownInt"].'</label>
						</td>
						<td>
							<select name = "intermed">';
			
	foreach ($intermediaires as $intermed)
	{
		if ($intermed->id != $_SESSION['userid'])
		{
			echo "					<option value='".$intermed->id."'>".$intermed->nom." ".$intermed->prenom." (".$intermed->login.")</option>";
		}
	}

	echo '					</select>
						</td>
					</tr>';
				
				
	echo '			<tr>
						<td>
							<label class = "text" for = "intermconnu">'.$language[$_SESSION['lang']]["ChangeToInt"].'</label>
						</td>
						<td>
							<select name = "vers">';
			
	foreach ($intermediaires as $intermed)
	{
		echo "					<option value='".$intermed->id."'>".$intermed->nom." ".$intermed->prenom." (".$intermed->login.")</option>";
	}

	echo '					</select>
						</td>
					</tr>
				</table>';
			
	echo '	<input type="submit" name="validersuppression" value="'.$language[$_SESSION['lang']]["Valid"].'">
			</form>
			</fieldset>';

}
else if (isset($_GET["ajouter"]))
{
	
	if (isset($intermediaireError))
	{
		echo '	<fieldset>
					<legend>'.$language[$_SESSION['lang']]["Information"].'</legend>
					'.$language[$_SESSION['lang']]["IntOrClientNotFound"].'.
				</fieldset>';
	}
	else if (isset($intermediaireSuccess))
	{
		echo '	<fieldset>
					<legend>'.$language[$_SESSION['lang']]["Information"].'</legend>
					'.$language[$_SESSION['lang']]["DemandIntSent"].'.
				</fieldset>';
	}

	echo '	<fieldset>
				<legend>'.$language[$_SESSION['lang']]["AddInt"].'</legend>
				<form method="POST">
					<input type="text" name="login" value="'.$language[$_SESSION['lang']]["Defaultlogin"].'" />
					<select name="location">';
	
	foreach ($goods as $good) {
		if ($good->ref_intermediaire == $_SESSION['userid'])
		{
			echo '<option value="'.$good->id_bien.'">'.$good->nom.'</option>';
		}
	}
	
					
	echo '				</select>
					<input type="submit" name="validerajout" value="'.$language[$_SESSION['lang']]["Valid"].'">
				</form>
			</fieldset>';

}
else
{
	
	foreach ($goods as $good) {
	echo '<fieldset>
				<legend>'.$good->nom.'</legend>
				'.$intermediaires[$good->ref_intermediaire]->civilite.' '.$intermediaires[$good->ref_intermediaire]->nom.' '.$intermediaires[$good->ref_intermediaire]->prenom.' ('.$intermediaires[$good->ref_intermediaire]->login.') 
				 | 
				 <form method="POST" class="formchangeintermed">
					<input type="hidden" name="good" value="'.$good->id_bien.'" />
					<input type="hidden" name="intermed" value="'.$intermediaires[$good->ref_intermediaire]->id.'" />';
					
	if (isset($_POST['good']) && isset($_POST["change"]))
	{
		echo '<select name = "vers">';
			
		foreach ($intermediaires as $intermed)
		{
			echo "					<option value='".$intermed->id."'>".$intermed->nom." ".$intermed->prenom." (".$intermed->login.")</option>";
		}

		echo '					</select>';
	
	}
									
	echo '			<input type="submit" value="'.$language[$_SESSION['lang']]["ChangeOfInt"].'" name="change" />
					<input type="submit" value="'.$language[$_SESSION['lang']]["DocForMiddleMan"].'" name="MMDoc" />
				</form>
			</fieldset>';
	
	}
	
}

require('footer.php');

?>
